package com.csj.mvvmtest

/*
* 通过by关键字将接口的实现委托给innerSet成员变量，需要修改的函数再去override就可以了
* */
class CountingSet2<T>(val innerSet: MutableCollection<T>) :
    MutableCollection<T> by innerSet {

    var objectAdded = 0

    override fun add(element: T): Boolean {
        ++objectAdded
        return innerSet.add(element)
    }

    override fun addAll(elements: Collection<T>): Boolean {
        objectAdded += elements.size
        return innerSet.addAll(elements)
    }
}